package com.palnar.ilecker.model;

import java.io.Serializable;

import org.ksoap2.serialization.SoapObject;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import com.palnar.ilecker.utils.XmlDocumentUtility;

public class Role implements Serializable {

	private Integer id = 0;
	private String name = "";

	private static String idArg = "Id";
	private static String nameArg = "Name";

	public Role(Integer id, String name) {
		this.id = id;
		this.name = name;
	}

	public Role() {

	}

	public Integer GetId() {
		return this.id;
	}

	public String GetName() {
		return this.name;
	}

	public void SetId(Integer id) {
		this.id = id;

	}

	public void SetName(String name) {
		this.name = name;
	}

	public void getSerializationData(Element parentElement, Document document) {

		Element idElement = document.createElement(idArg);
		Node idNode = document.createTextNode("id");
		idNode.setNodeValue(id.toString());
		idElement.appendChild(idNode);
		parentElement.appendChild(idElement);

		Element nameElement = document.createElement(nameArg);
		Node nameNode = document.createTextNode("name");
		nameNode.setNodeValue(name);
		nameElement.appendChild(nameNode);
		parentElement.appendChild(nameElement);

	}

	public static Role RoleTypeBuilder(SoapObject object) {

		
		
		Role role = new Role();

		Object idObj = object.getProperty(idArg);
		if(idObj != null)
		{
		if (!idObj.toString().equals(XmlDocumentUtility.nullString)) {
			role.SetId(Integer.parseInt(idObj.toString()));
		}
		}

		Object nameObj = object.getProperty(nameArg);
		if(nameObj != null)
		{
		if (!nameObj.toString().equals(XmlDocumentUtility.nullString)) {
			role.SetName(nameObj.toString());
		}
		}

		return role;
	}
}
